
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

/*---------------------------------------------------------
   Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()

	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS ) 
	
	self:SetColor(0,200,200,255)
	self:SetModel("models/items/combine_rifle_ammo01.mdl")
	
	self.Heal = Sound("items/battery_pickup.wav")
	self.LoopSound = Sound("ambient/machines/combine_terminal_loop1.wav")
	self.LoopTime = 2
	
	self.Aura = CurTime() + 5
	
	local phys = self:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableDrag(true)
		phys:EnableCollisions(true)
		phys:SetMass(900)
		//phys:EnableMotion(false)
	end
	
end

function ENT:Use(ply,caller)
	if not ply:Immune() then
		ply:VoiceSound(ChooseRandom(ply.Pickup),100,math.Rand(1,2))
		ply:SetImmune(true)
		ply:EmitSound(self.Heal,120,math.random(90,110))
		umsg.Start("HealthTiny", ply)
		umsg.End() 
		Inventory.Notice(ply, "Gained temporary immunity", Inventory.Blue)
	end
	if ply.InfectInterval or ply.PoisonInterval then
		Inventory.Notice(ply, "Neutralized all toxins", Inventory.Blue)
		ply:StopInfection()
		ply:StopPoison()
		ply:EmitSound(self.Heal,120,math.random(90,100))
	end
end

function ENT:PlayerFind()
	for k,ply in pairs(player.GetAll()) do
		if ply:Team() == TEAM_HUMANS then
			if ply:GetPos():Distance(self:GetPos()) < 250 then
				if not ply:Immune() then
					ply:VoiceSound(ChooseRandom(ply.Pickup),100,math.Rand(1,2))
					ply:SetImmune(true)
					ply:EmitSound(self.Heal,120,math.random(90,110))
					umsg.Start("HealthTiny", ply)
					umsg.End() 
					Inventory.Notice(ply, "Gained temporary immunity", Inventory.Blue)
				end
				if ply.InfectInterval or ply.PoisonInterval then
					Inventory.Notice(ply, "Neutralized all toxins", Inventory.Blue)
					ply:StopInfection()
					ply:StopPoison()
					ply:EmitSound(self.Heal,120,math.random(90,100))
				end
			end
		end
	end
end

/*---------------------------------------------------------
   Name: Think
---------------------------------------------------------*/
function ENT:Think()
	if not self.Timer then
		self.Timer = CurTime() + self.LoopTime
		self:PlayerFind()
	elseif CurTime() > self.Timer then
		self:EmitSound(ChooseRandom(GameSounds.Antidote),90,math.random(90,110))
		self.Timer = nil
	end
	if self.Aura then
		if CurTime() > self.Aura then
			self.Aura = nil
			local effectdata = EffectData()
			effectdata:SetOrigin(self:GetPos())
			util.Effect("antidote_aura", effectdata)
		end
	end
end 
 
function ENT:OnRemove()
	self:EmitSound(self.Heal,120,150)
end

 /*---------------------------------------------------------
   Name: takedamage
---------------------------------------------------------*/
function ENT:OnTakeDamage( dmginfo )	

end

/*---------------------------------------------------------
   Name: PhysicsCollide
---------------------------------------------------------*/
function ENT:PhysicsCollide( data, physobj )

end